package com.example.springboottx.mapper;

import com.example.springboottx.bean.Computer;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.cache.decorators.FifoCache;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;

//@Mapper
//@Repository
@Component
/*@CacheNamespace(flushInterval = 30000,
        size = 512,
        readWrite = true,
        eviction = FifoCache.class)*/
@CacheNamespaceRef(ComputerMapper.class)
public interface ComputerMapper {

    @Options()
    int insertComputer(Computer computer);

    Computer selectOneComputer(String name);

    @Insert("insert into computer(computer_name, computer_price, keyboard, mouse)\n" +
            "        values (#{computerName},\n" +
            "        #{computerPrice}, #{keyboard}, #{mouse})")
//    @SelectKey(keyProperty = "computerId",before = false,
//            resultType = int.class,statement = "select last_insert_id()")
    @Options(useGeneratedKeys = true, keyProperty = "computerId")
    int insertComputerTestSelectKey(Computer computer);

    @Select("select * from computer where computer_name=#{a} and computer_price=#{b}")
    Computer findOneBy2Param( String a,@Param("b") Integer bb);

    List<Computer> selectAllComputer(@Param("k") String keyboard,@Param("m") String mouse);

//    @Select("select * from computer where computer_name=#{computerName} and computer_price=#{computerPrice}")
    Computer findByMap(HashMap<String,String> map);
}
